<!DOCTYPE html>
<html>

{include file='public/header'}
<style>
    .message{
        color: red;
        font-weight: bold;
        margin-left: 20px;
        display: inline-block;
        text-align: center;
    }
</style>
<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="javascript:void(0)">首页</a>
            <a href="javascript:void(0)">投放管理</a>
            <a><cite>腾讯今日实时在投</cite></a>
        </span>
        <a class="layui-btn layui-btn-small" id="reload" title="刷新">
            <i class="layui-icon" style="line-height:30px"><i class="iconfont">&#xe6aa;</i></i>
        </a>
    </div>
    <div class="x-body">
        <div class="layui-row">
            <form class="layui-form">
                <div class="layui-inline">
                    <label class="layui-form-label w-auto">链接ID：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="link_id" placeholder="请输入链接ID" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label w-auto">负责人：</label>
                    <div id="pMenu" style="width:100%;flex:1"></div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label w-auto">选择短剧：</label>
                    <div id="pMenu1" style="width:100%;flex:1"></div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label w-auto">选择公司：</label>
                    <div id="pMenu2" style="width:100%;flex:1"></div>
                </div>

                <button class="layui-btn" style="margin-left: 10px;" lay-submit lay-filter="searchList">搜索</button>
                <button type="reset" id="resetList" class="layui-btn layui-btn-primary">重置</button>
            </form>
        </div>
        <table id="investing" lay-filter="investing"></table>
    </div>
    <script type="text/html" id="toolbarDemo">
        <blockquote class="layui-elem-quote layui-row" style="padding: 3px 15px;margin: 0;">
            <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">当前数据产生时间：
                <span id="create_time"></span>
                <div style="display: inline-block;color: black;">在投链接数（消耗）：
                    <span id="cont_num" class="layui-badge layui-bg-blue">0</span>
                </div>
            </div>
            <span class="message layui-col-xs12 layui-col-sm5 layui-col-md6"></div>
        </blockquote>
    </script>
    <script>
        var total_click_num,total_new_user;

        layui.use(["layer"], function () {
            let params = {
                elem: '#investing'
                , toolbar: '#toolbarDemo'
                , url: '/admin/launch/tencentInvesting' //数据接口
                , id: 'investing'
                , page:false
                , totalRow:true
                , height:'full-140'
                , cols: [[ //表头
                    { field: 'id', title: '链接ID' ,width:80, totalRowText: '合计：', align:'center' }
                    , { field: 'video_name', title: '短剧名称', align:'center', }
                    , { field: 'advertiser_id', title: '广告账户ID', width:155, align:'center' }
                    , { field: 'cost', title: '当天消耗', align:'center', sort: true, width:110, totalRow: '{{= d.TOTAL_NUMS.toFixed(2) }}'}
                    , { field: 'actual_cost', title:'实际消耗', align:'center', sort: true, width:110, totalRow: '{{= d.TOTAL_NUMS.toFixed(2) }}'}
                    , { field: 'balance', align:'center', title:'账户余额<i class="layui-icon iconfont icon-lytishi1" id="balance"></i>', sort: true, width:120, totalRow: '{{= d.TOTAL_NUMS.toFixed(2) }}'}
                    , { field: 'current_recharge', align:'center', title:'当天充值', sort: true, width:110, totalRow: '{{= d.TOTAL_NUMS.toFixed(2) }}'}

                    , { field: 'current_recharge_discount', align:'center', title:'当天收益', sort: true, width:110, totalRow: '{{= d.TOTAL_NUMS.toFixed(2) }}'}
                    , { field: 'current_recharge_profit', align:'center', title:'当天利润', sort: true, width:110, totalRow: '{{= d.TOTAL_NUMS.toFixed(2) }}'}

                    , { field: 'current_recovery', title:'返前ROI', align:'center', width:100 }
                    , { field: 'actual_recovery', title:'返后ROI', align:'center', width:100 }

                    , { field: 'conversion_number', title:'充值人数', align:'center', sort: true, width:102, totalRow: '{{= d.TOTAL_NUMS }}'}

                    , { field: 'echo_rate', title:'回传率',align:'center' , width:75}
                    , { field: 'new_user_number', title:'新充人数', align:'center', width:102, sort: true, totalRow: '{{= d.TOTAL_NUMS.toFixed() }}'}
                    , { field: 'conversion_cost', title:'转化成本', align:'center', width:102, sort: true}
                    , { field: 'conversion_rate', title:'转化率', align:'center', width:85 }
                    
                    , { field: 'new_recharge_number', title:'新充笔数', align:'center', width:102, sort: true, totalRow: '{{= d.TOTAL_NUMS.toFixed() }}'}
                    , { field: 'avg_person_order', title:'人均充值次数', align:'center', sort: true, width:130 }
                    , { field: 'fans_cost', title:'粉丝成本', align:'center', width:102, sort: true}
                    // , { field: 'total_recharge', title:'当天累计充值',width:130 , sort: true, totalRow: '{{= d.TOTAL_NUMS.toFixed(2) }}'}
                    
                    , { field: 'per_capita_contribution', title:'人均充值', width:102, align:'center', sort: true}
                    , { field: 'revenue', title:'盈收情况', sort: true, align:'center', width:102, totalRow: '{{= d.TOTAL_NUMS.toFixed(2) }}'}
                    , { field: 'responsibility_person_name', title:'负责人名称', width:102, align:'center'}
                ]],
                parseData:function (res) { //res 即为原始返回的数据
                    total_click_num = res.data.total_click_num
                    total_new_user = res.data.total_new_user
                    $('#create_time').html(res.data.create_time)
                    if(res.code == 200){
                        let num=0;
                        res.data.data.map(resut=>{
                            if(resut.cost>0){
                                num= num+1
                            }
                        })
                        $('#cont_num').html(num)
                        return {
                            "data": res.data?.data, //解析数据列表
                            "code": res.code, //解析接口状态
                            'count': 0//解析数据长度
                        }
                    }else{
                        // layer.msg(res.message,{icon:5,time:1000});
                        $('.message').html(res.message)
                        return {
                            "data": [], //解析数据列表
                            "code": 200, //解析接口状态
                            'count':0//解析数据长度
                        };
                    }
                },
                done: function(res, curr, count){
                    //然后把值写上去td[data-field="itemNo" 定义在哪个列后显示
                    const current_recharge = this.elem.next().find('.layui-table-total td[data-field="current_recharge"] .layui-table-cell').text(); // 当天充值
                    const cost = this.elem.next().find('.layui-table-total td[data-field="cost"] .layui-table-cell').text(); //巨量花费
                    const actual_cost = this.elem.next().find('.layui-table-total td[data-field="actual_cost"] .layui-table-cell').text(); // 实际花费
                    const new_user_number = this.elem.next().find('.layui-table-total td[data-field="new_user_number"] .layui-table-cell').text(); //当天新充人数
                    const new_recharge_number = this.elem.next().find('.layui-table-total td[data-field="new_recharge_number"] .layui-table-cell').text(); //新充笔数
                    const current_recharge_discount = this.elem.next().find('.layui-table-total td[data-field="current_recharge_discount"] .layui-table-cell').text(); // 当天收益

                    const current_recovery = Percentage(current_recharge_discount, cost); // 合计当天回收=合计当天充值/合计巨量花费
                    const actual_recovery = Percentage(current_recharge_discount, actual_cost); // 合计返后回收=合计当天充值/合计实际花费
                    const conversion_cost = perCapita(actual_cost, new_user_number); // 合计转化成本=合计实际花费/合计当天新充人数
                    const conversion_rate = Percentage(new_user_number,total_click_num);//合计转化率=合计当天新充人数/当天总点击数
                    const fans_cost = perCapita(actual_cost,total_new_user);//合计粉丝成本=合计当天总花费/当天总新增粉丝数
                    const per_capita_contribution = perCapita(current_recharge,new_user_number);//合计人均贡献值=合计当天充值/合计新充人数
                    const avg_person_order = perCapita(new_recharge_number,new_user_number);//合计人均充值次数=订单总数/合计充值人数
                    this.elem.next().find('.layui-table-total td[data-field="current_recovery"] .layui-table-cell').text(current_recovery + '%');
                    this.elem.next().find('.layui-table-total td[data-field="actual_recovery"] .layui-table-cell').text(actual_recovery + '%');
                    this.elem.next().find('.layui-table-total td[data-field="conversion_cost"] .layui-table-cell').text(conversion_cost);
                    this.elem.next().find('.layui-table-total td[data-field="conversion_rate"] .layui-table-cell').text(conversion_rate + '%');
                    this.elem.next().find('.layui-table-total td[data-field="fans_cost"] .layui-table-cell').text(fans_cost);
                    this.elem.next().find('.layui-table-total td[data-field="per_capita_contribution"] .layui-table-cell').text(per_capita_contribution);
                    this.elem.next().find('.layui-table-total td[data-field="avg_person_order"] .layui-table-cell').text(avg_person_order);

                    tips('#balance','#balance','在投链接账户余额')
                },
                
            }
            tableList(params)
        })
        let selectParams = {
            url:'/admin/responsibilityPerson/select?type=1',
            selected:[],
            tips:'请选择',
            name: 'responsibility_person_id',
            field_id:'responsibility_person_id',
            field_Name:'responsibility_person_name',
            elem: '#pMenu'
        }
        selectN(selectParams)

        let selectParams1 = {
            url: '/admin/video/select',
            selected: [],
            tips: '选择短剧',
            name: 'video_id',
            field_id: 'id',
            field_Name: 'name',
            elem: '#pMenu1'
        }
        selectN(selectParams1)

        let selectParams2 = {
            url: '/admin/company/select?type=1',
            selected: [],
            tips: '选择公司',
            name: 'company_id',
            field_id: 'id',
            field_Name: 'name',
            elem: '#pMenu2'
        }
        selectN(selectParams2)
    </script>
</body>

</html>